package com.shelpe.services.sinbad.entity.mongo;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.Document;

import com.shelpe.services.sinbad.entity.jpa.Adgroup;

import lombok.Data;

@Data
@Document(collection = "keyword_add_error_logs")
public class KeywordAddErrorLog {
	@Id
	private String id;
	@Indexed
	private long userID;
	@Indexed
	private long adgroupID;
	@Indexed
	private long campaignID;
	@Indexed
	private Date executeTime;
	@Indexed
	private String subCode;
	@Indexed
	private String subMessage;

	private String errorCode;
	private boolean fixed;

	private List<RecommendWord> words;
	private List<RecommendWord> successWords;
	private List<RecommendWord> addedWords;

	public void from(Adgroup adgroup) {
		this.userID = adgroup.getUserID();
		this.adgroupID = adgroup.getAutoID();
		this.campaignID = adgroup.getCampaignID();

		this.executeTime = new Date();
		this.id = this.adgroupID + "_" + this.executeTime.getTime();
	}

	public void addErrorWord(RecommendWord word) {
		if (this.words == null) {
			this.words = new ArrayList<RecommendWord>();
		}
		this.words.add(word);
	}

	public void addSuccessWord(RecommendWord word) {
		if (this.successWords == null) {
			this.successWords = new ArrayList<RecommendWord>();
		}
		this.successWords.add(word);
	}

	public void addAddedWord(RecommendWord word) {
		if (this.addedWords == null) {
			this.addedWords = new ArrayList<RecommendWord>();
		}
		this.addedWords.add(word);
	}

	@Data
	public static class RecommendWord {
		private String word;
		private int matchScope;
		private int maxPrice;

		private boolean fixed;
	}
}
